#!/usr/bin/env python3

import random

#  打印矩形
def rect(w, h):
    print("w = %d, h = %d" % (w, h))
    for r in range(h):
        for c in range(w):
            print(" *", end='')
        print()

    print("=======================")

    for r in range(h):
        print(" *" * w)

    print("=======================")
    for i in range(w * h):
        c = i % w
        print(" *", end='')
        if c == w - 1:
            print()

#打印直角形

def triangle(n):
    print("n = %d" % (n))
    #  for r in range(n):
        #  for c in range(r):
            #  print('  ', end='')
        #  for c in range(n - r):
            #  print(' *', end='')
        #  print()

    #  print("=======================")
    #  for r in range(n):
        #  print('  ' * r, ' *' * (n - r), sep='')

    print("=======================")
    for i in range(n * n):
        r, c = i // n, i % n
        ch = '* ' if c >= r else '  '
        print(ch, end='')
        if c == n - 1:
            print()

    print("=======================")
    for i in range(n * n):
        r, c = i // n, i % n
        ch = '* ' if c <= r else '  '
        print(ch, end='')
        if c == n - 1:
            print()

    print("=======================")
    for i in range(n * n):
        r, c = i // n, i % n
        ch = '* ' if c <= n - r - 1 else '  '
        print(ch, end='')
        if c == n - 1:
            print()

    print("=======================")
    for i in range(n * n):
        r, c = i // n, i % n
        ch = '* ' if c >= n - r - 1 else '  '
        print(ch, end='')
        if c == n - 1:
            print()


def fourBit():
    c = 0
    #  for i in range(4, 8):
        #  for j in range(4, 8):
            #  for k in range(4, 8):
                #  for l in range(4, 8):
                    #  if i == j or i == k or i == l           \
                            #  or j == k or j == l or k == l:
                        #  continue
                    #  n = i * 1000 + j * 100 + k * 10 + l
                    #  if n % 4 != 0:
                        #  print("%d " % (n), end='')
                        #  c += 1

    s = 4 + 5 + 6 + 7
    for i in range(4, 8):
        for j in range(4, 8):
            if i == j:
                continue
            for k in range(4, 8):
                if i == k or j == k:
                    continue
                l = s - i - j - k
                n = i * 1000 + j * 100 + k * 10 + l
                if n % 4 != 0:
                    print("%d " % (n), end='')
                    c += 1
    print("\nc = %d" % (c))


while True:
    print("\033[1;1H\033[2J", end='')
    print("1. 矩形")
    print("2. 直角三角形")
    print("3. 组合4位数")
    sel = int(input("请输入: "))
    print("-------------------------------------------")
    if sel == 1:
        rect(random.randint(1, 10), random.randint(1, 10))
    elif sel == 2:
        triangle(random.randint(3, 10))
    elif sel == 3:
        fourBit()
    elif sel == 0:
        break
    print("-------------------------------------------")
    sel = input("按回车继续选择菜单, 按q退出: ")
    if sel == 'q':
        break

